//
//  SNNoticesListCell.m
//  app
//
//  Created by 王少宁 on 15/8/20.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "SNNoticesListCell.h"

@interface SNNoticesListCell ()
@property (nonatomic, retain) UIImageView * picImageView;
@property (nonatomic, retain) UILabel * tiltleLable;
@property (nonatomic, retain) UILabel * introsLabel;
@property (nonatomic, retain) UILabel * viewsLabel;
@end

@implementation SNNoticesListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier shopBaseModel:(SNShopBaseModel *)model row:(NSInteger)row
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier shopBaseModel:model]) {
        
        SNShopNoticesListModel * noticesListModel = (SNShopNoticesListModel *)model;
        
        if (noticesListModel.notices_listArray.count) {
            [self crateCellWithModel:noticesListModel row:row];
        }
        
    }
    return self;
}

- (void)crateCellWithModel:(SNShopNoticesListModel *)shopModel row:(NSInteger)row
{
    if (!shopModel.notices_listArray.count) return;
    
    _picImageView = [[UIImageView alloc] initWithFrame:CGRectMake(15, 10, (shopModel.cellHeight - 20) * 1.5, shopModel.cellHeight - 20)];
    _picImageView.contentMode = UIViewContentModeScaleAspectFit;
//    _picImageView.layer.borderWidth = UP(1);
//    _picImageView.layer.borderColor = [XCommon hexStringToColor:kColor_gray_line].CGColor;
    [self.contentView addSubview:_picImageView];
    
    _tiltleLable = CREATE_WITH_FRAME_OF(UILabel, [_picImageView.ufo fx:1.0 ox:18 fy:0],
                                                   [self.contentView.ubo ow:SCREEN_WIDTH - 15 - 18 - _picImageView.ufo.xx oh:15]);
    _tiltleLable.font = JKAppGlobleFontSmallTagText;
    [self.contentView addSubview:_tiltleLable];
    
    _introsLabel = CREATE_WITH_FRAME_OF(UILabel, [_tiltleLable.ufo fx:0 fy:1.0 oy:2],
                                                 [_tiltleLable.ubo fw:1.0 fh:1.0]);
    _introsLabel.font = [UIFont systemFontOfSize:12.0f];
    _introsLabel.textColor = [XCommon hexStringToColor:@"#939393"];
    [self.contentView  addSubview:_introsLabel];
    
    _viewsLabel = CREATE_WITH_FRAME_OF(UILabel, [_introsLabel.ufo fx:1.0 ox:-55 fy:1.0 oy:2],
                                                [_introsLabel.ubo ow:55 oh:20]);
    _viewsLabel.font = JKAppGlobleFontMinTagText;
    _viewsLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_viewsLabel];
    
    UIButton * mainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mainBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH, shopModel.cellHeight);
    mainBtn.tag = row + 1;
    [mainBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:mainBtn];
}

- (void)cellWithModel:(SNShopNoticesListSubModel *)model
{
    [_picImageView sd_setImageWithURL:[NSURL URLWithString:model.title_pic]];
    _tiltleLable.text = model.title;
    _introsLabel.text = model.intros;
    _viewsLabel.text = [NSString stringWithFormat:@"%@ 浏览",model.views];
}

- (void)btnClick:(UIButton *)btn
{
    if ([self.delegate respondsToSelector:@selector(itemClickWithShopBaseModel:row:index:)]) {
        [self.delegate itemClickWithShopBaseModel:self.shopBaseModel row:0 index:btn.tag - 1];
    }
}

- (void)cellBtnClick:(UIButton *)btn
{
    
}

- (void)drawRect:(CGRect)rect {
    [self drawHorizonLineLeft:15 right:15 at:rect.size.height - UP(1)];
}

@end
